The present invention relates to computer systems having multiple parallel processors, and more particularly to a method for a process requiring access to another process that is currently occupied to determine the most advantageous action to take until the required process is not occupied.
In systems with multiple parallel processors, data and resources are typically shared by the various tasks being performed by the processors. Any time data are shared among multiple processors in a system, some facility must be provided to ensure the coherency of the shared data. This means that while one processor has access to the shared data, no other processor may access and change the shared data. Similarly some facility must be provided to ensure the coherency of data provided to a shared resource and its software interface. For example, something must prevent two or more processors from outputting data from two different files to a shared printer at the same time. Otherwise, the page printed may have characters and words that are an unintelligible and incoherent admixture of the two data files.
A typical way to ensure the coherency of shared data and shared resources in "UNIX" computer systems ("UNIX" is a registered trademark of AT&T Corporation) and computer systems with operating systems similar to "UNIX" is to provide a synchronization lock for the shared data or resource. The synchronization lock locks out access by another processor or process until the current process, referred to as the owner, has completed its access.
The capability to lock out all other processes and processors for the period of the required access is provided by the synchronization lock. This is accomplished by a portion of the process that accesses the shared data or resource first requesting ownership of the synchronization lock by means of a locking synchronization process, called a primitive, before actually accessing the shared data or resource. If the synchronization lock is not owned at the time, the requesting process is assigned ownership of the requested synchronization lock and the requesting and owning process makes the necessary access to the shared data or resource. After the access is completed, the requesting and owning process releases the shared data or resource by means of an unlocking synchronization primitive. Such operation is well known by those versed in operating the "UNIX" operating system.
A problem arises when a second process requests access to a shared process that is currently occupied by some process. In such a case when the second process requests ownership of the synchronization lock of the shared data or resource, the second process will discover from the synchronization lock data that such ownership is not currently possible. Since the requested shared data or resource is not available, the second process can take one of two options: it can wait briefly and try again which is often referred to as "spinning", or it can store its present status and enter a "sleep" mode in which the second process is inactive until the requested data or resource is available again. Spinning wastes processing time because no useful work is accomplished by the processor of the second process while it is waiting for the requested process. Sleeping wastes processing time because while the second process sleeps, its processor unloads the context and the data of the second process and begins to load and run a third process; therefore, when the requested shared data or resource is available again, the second process must be awakened and reloaded. Thus, for short waits spinning is best because context switching and loading times are saved, and for long waits sleeping is best because another process can use the processor while the second requesting process is sleeping. Unfortunately, the second requesting process cannot know if it will have a short wait (and therefore it should spin) or a long wait (and therefore it should sleep).
Therefore, it is an object of this invention to provide a method for advising a requesting process of a preferred process of waiting until the requesting process obtains ownership of a synchronization lock of a requested process that is not currently available.
It is another object of this invention to provide a method for indicating to a requesting process that a synchronization lock is not currently available and advising the requesting process approximately how long it will be until the synchronization lock will be available again.
It is a further object of this invention to provide a method for providing advice and revising advice to a requesting process regarding a preferred process of waiting until the requesting process obtains ownership of a synchronization lock associated with the requested process.